package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.*;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogBusyFarmingDaoImpl extends TempDao {

    public boolean addLogBusyFarmingPlantList(List<LogBusyFarmingPlant> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_busy_farming_plant(activityId,userId,landId,seedId,logTime) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogBusyFarmingPlant data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSeedId()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogBusyFarmingLandBuyList(List<LogBusyFarmingLandBuy> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_busy_farming_land_buy(activityId,userId,landId,num,logTime) VALUES(?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogBusyFarmingLandBuy data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNum()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogBusyFarmingRemoveList(List<LogBusyFarmingRemove> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_busy_farming_remove(activityId,userId,landId,seedId,harvestTime,logTime) VALUES(?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogBusyFarmingRemove data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSeedId()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getHarvestTime())));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogBusyFarmingHarvestList(List<LogBusyFarmingHarvest> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_busy_farming_harvest(activityId,userId,landId,seedId,fruitNum,quickenTimes,beWateringTimes,stolenTimes,harvestTime,logTime) VALUES(?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogBusyFarmingHarvest data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSeedId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getFruitNum()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getQuickenTimes()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBeWateringTimes()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getStolenTimes()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getHarvestTime())));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogBusyFarmingQuickenList(List<LogBusyFarmingQuicken> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_busy_farming_quicken(activityId,userId,landId,seedId,num,harvestTime,logTime) VALUES(?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogBusyFarmingQuicken data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSeedId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNum()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getHarvestTime())));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogBusyFarmingStealList(List<LogBusyFarmingSteal> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_busy_farming_steal(activityId,userId,landId,seedId,enemyUserId,num,logTime) VALUES(?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogBusyFarmingSteal data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSeedId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getEnemyUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNum()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogBusyFarmingWateringList(List<LogBusyFarmingWatering> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_busy_farming_watering(activityId,userId,landId,seedId,friendUserId,logTime) VALUES(?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogBusyFarmingWatering data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLandId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSeedId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getFriendUserId()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
